package conMgr.model.tests;

import static org.junit.Assert.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


import org.junit.Test;

import conMgr.model.Conference;
import conMgr.model.Paper;
import conMgr.model.User;
import conMgr.model.UserType;
import conMgr.util.ObservableList;

public class ConferenceTest {

	@Test
	public void testConference() throws ParseException {
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.PROGRAM_CHAIR);
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		assertNotNull(conf_1.getName());
		assertNotNull(conf_1.getReviewDL());
		assertNotNull(conf_1.getRevisionDL());
		assertNotNull(conf_1.getSubmissionDL());
		assertNotNull(conf_1.getRecommendationDL());
		assertNotNull(conf_1.getProgramChair());
	}
	
	@Test
	public void testGetSubProgramChairs() throws ParseException{
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.SUBPROGRAM_CHAIR);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		
		ObservableList<User> subprogramChairs = conf_1.getSubprogramChairs();
		assertNotNull(subprogramChairs);
		
		conf_1.getSubprogramChairs().add(user_1);
		assertEquals(1, conf_1.getSubprogramChairs().size());
		assertEquals(user_1, conf_1.getSubprogramChairs().get(0));
		
	}
	
	@Test
	public void testGetReviewers() throws ParseException{
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		ObservableList<User> reviewers = conf_1.getReviewers();
		
		assertNotNull(reviewers);		
		conf_1.getReviewers().add(user_1);
		assertEquals(1, conf_1.getReviewers().size());
		assertEquals(user_1, conf_1.getReviewers().get(0));
	}
	

	@Test
	public void testGetPapers() throws ParseException{
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, null, null, null, null);
		ObservableList<Paper> papers = conf_1.getPapers();
		
		assertNotNull(papers);		
		conf_1.getPapers().add(paper_1);
		assertEquals(2, conf_1.getPapers().size());
		assertEquals(paper_1, conf_1.getPapers().get(1));
	}
	
	@Test
	public void testGetAllConferences() throws ParseException {
		Conference.getAllConferences().clear();
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Anna", "Anna@mail.ru", UserType.PROGRAM_CHAIR);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Conference conf_2 = new Conference("Conf 2", user_1, date_1	, date_2, date_3, date_4);
		Conference conf_3 = new Conference("Conf 3", user_1, date_1	, date_2, date_3, date_4);
		ObservableList<Conference> list = new ObservableList<Conference>();
		list.add(conf_1);
		list.add(conf_2);
		list.add(conf_3);
		
		assertNotNull(list);
		assertEquals(3, list.size());
		assertEquals(list.size(), Conference.getAllConferences().size());
		
	}

}
